package pantallas;

import gestores.GestorPedidos;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import negocio.Mesa;
import controlador.Controlador;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CerrarMesaView extends javax.swing.JFrame {
	private JLabel lblCodigoMesa;
	private JButton cmdCancelar;
	private JButton cmdCerrarMesa;
	private JTextField txtTotalMesa;
	private JLabel lblTotalMesa;
	private JComboBox cmbCodigoMesa;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CerrarMesaView inst = new CerrarMesaView();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public CerrarMesaView() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			this.setSize(375, 201);
			getContentPane().setLayout(null);
			setTitle("Cerrar Mesa");
			{
				lblCodigoMesa = new JLabel();
				getContentPane().add(lblCodigoMesa);
				lblCodigoMesa.setText("Codigo de Mesa");
				lblCodigoMesa.setBounds(28, 33, 116, 14);
			}
			{
				ComboBoxModel cmbCodigoMesaModel = 
						new DefaultComboBoxModel(
								new String[] {});
				cmbCodigoMesa = new JComboBox();
				getContentPane().add(cmbCodigoMesa);
				cmbCodigoMesa.setModel(cmbCodigoMesaModel);
				cmbCodigoMesa.setBounds(175, 30, 141, 21);
				for(Mesa mesa : GestorPedidos.getInstance().getMesas())
					cmbCodigoMesa.addItem(mesa.getNroMesa());
			}
			{
				lblTotalMesa = new JLabel();
				getContentPane().add(lblTotalMesa);
				lblTotalMesa.setText("Total Mesa");
				lblTotalMesa.setBounds(28, 71, 147, 14);
			}
			{
				txtTotalMesa = new JTextField();
				getContentPane().add(txtTotalMesa);
				txtTotalMesa.setBounds(175, 68, 141, 21);
				txtTotalMesa.setEditable(false);
			}
			{
				cmdCerrarMesa = new JButton();
				getContentPane().add(cmdCerrarMesa);
				cmdCerrarMesa.setText("Cerrar Mesa");
				cmdCerrarMesa.setBounds(28, 119, 116, 21);
				cmdCerrarMesa.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent arg0) {
						// TODO Auto-generated method stub

						txtTotalMesa.setText(Integer.toString((int)Controlador.getInstance().CerrarMesa(Integer.parseInt(cmbCodigoMesa.getSelectedItem().toString()))));
//						if(!cmbCodigoMesa.getSelectedItem().toString().equals(""))
//						{
//							if(cmbCodigoMesa.getSelectedItem().toString().equals("1"))
//								txtTotalMesa.setText("206");
//							else if(cmbCodigoMesa.getSelectedItem().toString().equals("2"))
//								txtTotalMesa.setText("96");
//							else if(cmbCodigoMesa.getSelectedItem().toString().equals("3"))
//								txtTotalMesa.setText("202");
//							else if(cmbCodigoMesa.getSelectedItem().toString().equals("3"))
//								txtTotalMesa.setText("193");
//							else if(cmbCodigoMesa.getSelectedItem().toString().equals("1001"))
//								txtTotalMesa.setText("176");
//							else if(cmbCodigoMesa.getSelectedItem().toString().equals("9"))
//								txtTotalMesa.setText("189");
//							else 
//								txtTotalMesa.setText("158");
//						}
//						else
//							JOptionPane.showMessageDialog(null, "La cantidad de los platos debe ser mayor a cero.");
				
					}
				});
			}
			{
				cmdCancelar = new JButton();
				getContentPane().add(cmdCancelar);
				cmdCancelar.setText("Cancelar");
				cmdCancelar.setBounds(200, 119, 116, 21);
				cmdCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("cmdSalir.actionPerformed, event="+evt);
						dispose();
					}
				});
			}
			
			//MEDIDAS Y CENTRALIZACION DE LA PANTALLA.
	        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	        int w = this.getSize().width;
	        int h = this.getSize().height;
	        int x = (dim.width-w)/2;
	        int y = (dim.height-h)/2;
	        this.setLocation(x, y);
			this.setSize(336, 184);

		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
